package com.huawei.appgallery.wishwall.ui.fragment;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.Layout;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse;
import com.huawei.appgallery.wishwall.api.IWishWallReplyFragmentProtocol;
import com.huawei.appgallery.wishwall.api.IWishWallReplyFragmentProtocol.Request;
import com.huawei.appgallery.wishwall.ui.cardkit.bean.WishWallAppSelectionCardBean;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import huawei.widget.HwAlphaIndexerListView;
import huawei.widget.HwButton;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import o.bjy;
import o.cfw;
import o.HcridSession;
import o.chd;
import o.chg;
import o.cia;
import o.cih;
import o.cip;
import o.cja;
import o.BaseAlertDialog;
import o.BaseAlertDialog.a;
import o.cks;
import o.cvt;
import o.cvv;
import o.cvx;
import o.dbr;
import o.dbt;
import o.dbw;
import o.ddq.d;
import o.ddq.f;
import o.dds;
import o.ddu;
import o.ddw;
import o.deb;
import o.def;
import o.dgm;
import o.dmi;
import o.dmq;
import o.dnw;
import o.doo;
import o.ContentManager;
import o.epk;
import o.epl;
import o.epv;
import o.ActivityUtil;
import o.evk;
import o.evx;
import o.fps;
import org.json.JSONObject;

public class WishWallReplyFragment<T extends IWishWallReplyFragmentProtocol> extends BaseListFragment<T> {
    private BroadcastReceiver ʹ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ WishWallReplyFragment ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent == null || intent.getData() == null) {
                ddu.ˊ.ˊ("WishWallReplyFragment", "error intent");
                return;
            }
            Object schemeSpecificPart = intent.getData().getSchemeSpecificPart();
            if (TextUtils.isEmpty(schemeSpecificPart)) {
                ddu.ˊ.ˊ("WishWallReplyFragment", "error packageName");
                return;
            }
            String action = intent.getAction();
            ddu.ˊ.ˋ("WishWallReplyFragment", "WishWallReplyFragment" + " apkChangedReceiver, action = " + action + "," + "packageName:" + schemeSpecificPart);
            if ("android.intent.action.PACKAGE_ADDED".equals(action)) {
                this.ˋ.ᐝ(Arrays.asList(new String[]{schemeSpecificPart}));
            } else if ("android.intent.action.PACKAGE_REMOVED".equals(action)) {
                this.ˋ.ʻ(Arrays.asList(new String[]{schemeSpecificPart}));
            } else if ("android.intent.action.PACKAGE_CHANGED".equals(action)) {
                this.ˋ.ᐝ(Arrays.asList(new String[]{schemeSpecificPart}));
            }
        }
    };
    private HwButton ʼ;
    private List<def> ʽ = new ArrayList();
    private String ˊ;
    private String ˋ;
    private IWishWallReplyFragmentProtocol ˎ;
    fps ˏ;
    HwAlphaIndexerListView ॱ;
    private def ॱॱ;
    private LinearLayout ᐝ;
    private e ﾞ;
    private dds ﾟ;

    public interface c {
        void ˎ(boolean z);
    }

    class e implements o.dbt.e {
        private dbt ʻ;
        private boolean ʼ = false;
        private Context ˊ;
        private String ˋ;
        private deb ˎ;
        final /* synthetic */ WishWallReplyFragment ˏ;
        private def ॱ;
        private BaseAlertDialog ᐝ;

        e(WishWallReplyFragment wishWallReplyFragment, @NonNull Context context, @NonNull def o_def, @NonNull String str) {
            this.ˏ = wishWallReplyFragment;
            this.ˊ = context;
            this.ॱ = o_def;
            this.ˋ = str;
        }

        void ˊ() {
            this.ʼ = true;
            Map hashMap = new HashMap();
            hashMap.put("file", new File(this.ॱ.ˎ()));
            this.ʻ = new dbt(hashMap, ˏ(), this);
            dmq.ˏ.ॱ(this.ʻ);
            this.ˎ = ˊ(this.ˊ, this.ॱ);
            this.ˎ.show();
        }

        private dbw ˏ() {
            return new dbr(this) {
                final /* synthetic */ e ˋ;

                {
                    this.ˋ = r1;
                }

                public Map<String, String> ˋ() {
                    ddu.ˊ.ˎ("ApkUploadHelper", "start genParams...");
                    Map<String, String> linkedHashMap = new LinkedHashMap();
                    ˎ(linkedHashMap, HwPayConstant.KEY_SIGN, this.ˋ.ˋ);
                    ˎ(linkedHashMap, "ts", String.valueOf(System.currentTimeMillis()));
                    ˎ(linkedHashMap, "method", "client.user.replyWishWall");
                    ˎ(linkedHashMap, "sha256", dnw.ˎ(this.ˋ.ॱ.ˎ(), AaidIdConstant.SIGNATURE_SHA256));
                    ˎ(linkedHashMap, "wishId", this.ˋ.ˏ.ˋ);
                    o.bjy.c ॱ = new bjy(ContentManager.getInstant().getContext()).ॱ();
                    ˎ(linkedHashMap, "deviceId", ॱ.ˎ);
                    ˎ(linkedHashMap, "deviceIdType", String.valueOf(ॱ.ॱ));
                    ˎ(linkedHashMap, "clientPackage", this.ˋ.ˏ.ॱˋ().getPackageName());
                    ˎ(linkedHashMap, "serviceType", String.valueOf(dgm.ˎ(this.ˋ.ˏ.ॱˋ())));
                    ˎ(linkedHashMap, "net", String.valueOf(doo.ˏ(this.ˋ.ˏ.ॱˋ())));
                    ˎ(linkedHashMap, "code", epl.ॱ().ˎ());
                    try {
                        ˎ(linkedHashMap, "authorization", epk.ˏ().toJson());
                    } catch (Exception e) {
                        ddu.ˊ.ˊ("ApkUploadHelper", e.toString());
                    }
                    return linkedHashMap;
                }

                public boolean ॱ(String str) {
                    try {
                        int i = new JSONObject(str).getInt("rtnCode");
                        if (i == 0) {
                            return true;
                        }
                        ddu.ˊ.ˏ("ApkUploadHelper", "upload apk, parseResult failed. rtnCode:" + i);
                        return false;
                    } catch (Exception e) {
                        ddu.ˊ.ˏ("ApkUploadHelper", "uploadWishInfo(), parseResult exception " + e.toString());
                        return false;
                    }
                }

                public String ॱ() {
                    return cvx.ˎ("server.store") + "clientApi";
                }
            };
        }

        private deb ˊ(Context context, def o_def) {
            deb o_deb = new deb(context);
            o_deb.setCanceledOnTouchOutside(false);
            o_deb.ˋ(context.getString(f.ˌ, new Object[]{o_def.ˏ()}));
            o_deb.ॱ(0.0f);
            o_deb.setOnDismissListener(new OnDismissListener(this) {
                final /* synthetic */ e ˋ;

                {
                    this.ˋ = r1;
                }

                public void onDismiss(DialogInterface dialogInterface) {
                    if (this.ˋ.ʼ) {
                        this.ˋ.ˋ();
                    }
                }
            });
            return o_deb;
        }

        private void ˋ() {
            this.ᐝ = BaseAlertDialog.ˋ(this.ˊ, null, this.ˊ.getString(f.ˊˋ));
            this.ᐝ.ॱ();
            this.ᐝ.ˎ(new cks(this) {
                final /* synthetic */ e ˏ;

                {
                    this.ˏ = r1;
                }

                public void enableNetworking() {
                    if (this.ˏ.ʻ != null) {
                        this.ˏ.ʻ.ˎ();
                    }
                }

                public void upgrade() {
                    if (this.ˏ.ʼ) {
                        this.ˏ.ˎ.show();
                    }
                }

                public void ˋ() {
                }
            });
            this.ᐝ.ˎ(true);
            this.ᐝ.ˊ(new OnCancelListener(this) {
                final /* synthetic */ e ˊ;

                {
                    this.ˊ = r1;
                }

                public void onCancel(DialogInterface dialogInterface) {
                    if (this.ˊ.ʼ) {
                        this.ˊ.ˎ.show();
                    }
                }
            });
            this.ᐝ.ॱ(a.CONFIRM, this.ˊ.getString(f.ʼॱ));
            this.ᐝ.ॱ(a.CANCEL, this.ˊ.getString(f.ʿ));
        }

        public void ॱ() {
            this.ʼ = false;
        }

        public void ˋ(boolean z) {
            this.ʼ = false;
            if (this.ᐝ != null && this.ᐝ.ˎ()) {
                this.ᐝ.ˏ();
            }
            this.ᐝ = null;
            if (this.ˎ != null && this.ˎ.isShowing()) {
                this.ˎ.dismiss();
            }
            this.ˎ = null;
            if (z) {
                evk.ॱ(ContentManager.getInstant().getContext().getString(f.ˉ), 0).ˋ();
                Activity activity = (Activity) this.ˊ;
                if (activity instanceof c) {
                    ((c) activity).ˎ(true);
                }
                activity.finish();
                return;
            }
            new Builder(this.ˊ).setMessage(this.ˊ.getString(f.ˋˊ)).setCancelable(true).setNeutralButton(this.ˊ.getString(f.ˊᐝ), null).show();
        }

        public void ˋ(float f) {
            if (this.ʼ) {
                ddu.ˊ.ˎ("ApkUploadHelper", "upload progress = " + f);
                if (this.ˎ != null && this.ˎ.isShowing()) {
                    this.ˎ.ॱ(f);
                }
            }
        }
    }

    public cia ˊ(Context context) {
        cia o_cia = new cia(context);
        new chg().ॱ(o_cia, new chd(), ˎ(new ArrayList()), false);
        o_cia.ˊ(false);
        this.ﾟ = new dds(ॱˊ(), o_cia);
        return o_cia;
    }

    @NonNull
    private BaseDetailResponse ˎ(@NonNull List<def> list) {
        Layout layout = new Layout();
        layout.ॱ((long) 1);
        layout.ˋ(-1);
        layout.ˏ("wishwallreplycard");
        LayoutData layoutData = new LayoutData();
        layoutData.ˋ((long) 1);
        layoutData.ॱ("wishwallreplycard");
        List arrayList = new ArrayList();
        for (def o_def : list) {
            WishWallAppSelectionCardBean wishWallAppSelectionCardBean = new WishWallAppSelectionCardBean();
            wishWallAppSelectionCardBean.ˏˎ(o_def.ˋ());
            wishWallAppSelectionCardBean.appInfo = o_def;
            arrayList.add(wishWallAppSelectionCardBean);
        }
        layoutData.ॱ(arrayList);
        BaseDetailResponse baseDetailResponse = new BaseDetailResponse();
        arrayList = new ArrayList();
        arrayList.add(layout);
        baseDetailResponse.ˊ(arrayList);
        List arrayList2 = new ArrayList();
        arrayList2.add(layoutData);
        baseDetailResponse.ॱ(arrayList2);
        baseDetailResponse.ˏ(0);
        return baseDetailResponse;
    }

    public void ˏ(Bundle bundle) {
        this.ˎ = (IWishWallReplyFragmentProtocol) ˆ();
        if (this.ˎ != null && this.ˎ.ˎ() != null) {
            this.ˊ = ((Request) this.ˎ.ˎ()).ˋᐝ();
            this.ˋ = ((Request) this.ˎ.ˎ()).ˌ();
            ᐝॱ(false);
            dmq.ˏ.ॱ(new ddw(ॱˊ(), new b(this) {
                final /* synthetic */ WishWallReplyFragment ˋ;

                {
                    this.ˋ = r1;
                }

                public void ˎ(final List<def> list) {
                    ddu.ˊ.ˎ("WishWallReplyFragment", "onQueryInstalledApps count = " + list.size());
                    dmq.ॱ.ˊ(new dmi(this) {
                        final /* synthetic */ AnonymousClass3 ˋ;

                        public void run() {
                            if (ActivityUtil.isAcitivtyNotValid(this.ˋ.ˋ.ॱˋ()) || !this.ˋ.ˋ.ʾ()) {
                                ddu.ˊ.ˎ("WishWallReplyFragment", "fragment destroyed");
                            } else {
                                this.ˋ.ˋ.ʼ(list);
                            }
                        }
                    });
                }
            }));
            super.ˏ(bundle);
        }
    }

    public void ˌॱ() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.PACKAGE_ADDED");
        intentFilter.addAction("android.intent.action.PACKAGE_REMOVED");
        intentFilter.addAction("android.intent.action.PACKAGE_CHANGED");
        intentFilter.addDataScheme(HiAnalyticsConstant.BI_KEY_PACKAGE);
        ContentManager.getInstant().getContext().registerReceiver(this.ʹ, intentFilter);
    }

    public void ˋʼ() {
        ContentManager.getInstant().getContext().unregisterReceiver(this.ʹ);
    }

    private void ᐝ(List<String> list) {
        dmq.ˏ.ॱ(new ddw(ॱˊ(), list, new b(this) {
            final /* synthetic */ WishWallReplyFragment ˏ;

            {
                this.ˏ = r1;
            }

            public void ˎ(final List<def> list) {
                ddu.ˊ.ˎ("WishWallReplyFragment", "onQueryInstalledApps count = " + list.size());
                dmq.ॱ.ˊ(new dmi(this) {
                    final /* synthetic */ AnonymousClass5 ˏ;

                    public void run() {
                        if (ActivityUtil.isAcitivtyNotValid(this.ˏ.ˏ.ॱˋ()) || !this.ˏ.ˏ.ʾ()) {
                            ddu.ˊ.ˎ("WishWallReplyFragment", "fragment destroyed");
                        } else {
                            this.ˏ.ˏ.ʽ(list);
                        }
                    }
                });
            }
        }));
    }

    private void ʻ(List<String> list) {
        if (this.ॱॱ != null && list.contains(this.ॱॱ.ˋ())) {
            this.ʼ.setEnabled(false);
            this.ॱॱ = null;
        }
        Iterator it = this.ʽ.iterator();
        while (it.hasNext()) {
            if (list.contains(((def) it.next()).ˋ())) {
                it.remove();
            }
        }
        ॱˊ(this.ʽ);
    }

    private void ʽ(List<def> list) {
        if (this.ʽ == null) {
            ॱˊ(list);
            return;
        }
        for (def o_def : this.ʽ) {
            if (!list.contains(o_def)) {
                list.add(o_def);
            }
        }
        ॱˊ(list);
    }

    private void ʼ(List<def> list) {
        ॱˋ(true);
        ॱˊ(list);
        ॱˎ(0);
        this.ᐝ.setVisibility(0);
    }

    private void ॱˊ(List<def> list) {
        if (list.size() == 0) {
            this.ॱ.setVisibility(8);
            return;
        }
        this.ॱ.setVisibility(0);
        this.ﾟ.ॱ(list, this.ˊ, this.ـॱ);
        this.ʽ = this.ﾟ.ˊ();
        ˎ(this.ͺˎ, this.ﾟ.ॱ());
        this.ˏ = new fps(this.ͺˎ, this.ॱ);
        this.ˏ.ˊ();
    }

    private void ˎ(ListView listView, BaseAdapter baseAdapter) {
        Parcelable onSaveInstanceState = listView.onSaveInstanceState();
        listView.setAdapter(baseAdapter);
        listView.onRestoreInstanceState(onSaveInstanceState);
    }

    public void ᵔ() {
        ˎ(this.ॱˍ);
    }

    public int ߵ() {
        return o.ddq.c.ॱˋ;
    }

    public void ˋ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        super.ˋ(viewGroup, layoutInflater);
        this.ᐝ = (LinearLayout) viewGroup.findViewById(d.ʼ);
        this.ॱ = (HwAlphaIndexerListView) viewGroup.findViewById(d.ˎ);
        this.ʼ = (HwButton) viewGroup.findViewById(d.ˍ);
        this.ʼ.setEnabled(false);
        this.ʼ.getLayoutParams().width = epv.ˎ(ॱˋ()) / 2;
        this.ʼ.setOnClickListener(new evx(this) {
            final /* synthetic */ WishWallReplyFragment ॱ;

            {
                this.ॱ = r1;
            }

            public void ˋ(View view) {
                if (this.ॱ.ॱॱ != null) {
                    if (doo.ˊ(this.ॱ.ॱˊ())) {
                        this.ॱ.ﾞ = new e(this.ॱ, this.ॱ.ॱˋ(), this.ॱ.ॱॱ, this.ॱ.ʻ(dgm.ˎ(this.ॱ.ॱˋ())));
                        this.ॱ.ﾞ.ˊ();
                        return;
                    }
                    evk.ॱ(ContentManager.getInstant().getContext().getString(f.ˎ), 0).ˋ();
                }
            }
        });
        if (ʼʻ()) {
            ॱˎ(0);
            this.ᐝ.setVisibility(0);
            return;
        }
        ॱ(layoutInflater);
    }

    public void ˏ(int i, cih o_cih) {
        if (this.ʽ != null) {
            WishWallAppSelectionCardBean wishWallAppSelectionCardBean = (WishWallAppSelectionCardBean) o_cih.ˌ();
            if (wishWallAppSelectionCardBean.appInfo == null) {
                return;
            }
            if (this.ॱॱ == null || !wishWallAppSelectionCardBean.appInfo.ˋ().equals(this.ॱॱ.ˋ())) {
                this.ॱॱ = wishWallAppSelectionCardBean.appInfo;
                this.ʼ.setEnabled(true);
                for (def o_def : this.ʽ) {
                    o_def.ॱ(o_def.ˋ().equals(wishWallAppSelectionCardBean.appInfo.ˋ()));
                }
                this.ﾟ.ॱ().notifyDataSetChanged();
            }
        }
    }

    public cja ߴ() {
        return new cip();
    }

    private String ʻ(int i) {
        String ˏ = HcridSession.ˋ().ˏ(i);
        if (!TextUtils.isEmpty(ˏ)) {
            return ˏ;
        }
        cvt ˎ = cvv.ˎ();
        ˎ.setServiceType_(i);
        ResponseBean ॱ = cfw.ॱ(ˎ);
        if ((ॱ instanceof StartupResponse) && ॱ.getRtnCode_() == 0 && ॱ.getResponseCode() == 0) {
            ((StartupResponse) ॱ).ˎ(ˎ);
        }
        return HcridSession.ˋ().ˏ(i);
    }
}
